<div class="box box-primary box-thanhtoan">
    <div class="box-header">
        <h3 class="box-title">Thanh toán hóa đơn</h3>
    </div><!-- /.box-header -->
    <!-- form start -->
    <form role="form" id="form_thanhtoan">
        <?php foreach ($arrs as $key): ?>
            <input type="hidden" name="idhoadon[]" value="<?php echo $key; ?>">
        <?php endforeach ?>
        <div class="box-body">
            <div class="form-group">
                <label for="exampleInputEmail1">Tên thành viên:</label>
                <?php echo $model->ten; ?>
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Mã số khách hàng:</label>
                <?php echo $model->ma_so; ?>
            </div>
            <input type="hidden" value="<?php echo $model->id; ?>" name="id">
            <div class="form-group">
                <label for="exampleInputPassword1">Số tiền:</label>
                <?php if ($count == 1): ?>
                    <input type="text" id="tien" class="form-control input_text"  id="exampleInputPassword1" placeholder="Số tiền:" value="<?php echo $tongtien; ?>">
                    <input type="hidden" id="tong_tien" class="form-control input_text" class="hidden_so_tien" value="<?php echo $tongtien; ?>">
                    <input type="hidden" id="value_tien" class="form-control input_text"name="so_tien"  class="hidden_so_tien" value="">
                <?php else: ?>
                    <?php echo getMoney($tongtien); ?>
                <?php endif; ?>
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">Ngày thanh toán:</label>
                <input type="text" id="date" name="date" class="form-control input_text">
                <script type="text/javascript">$('#date').datepicker();</script>
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">Số chứng từ:</label>
                <input type="text" id="so_chungtu" class="form-control input_text" name="so_chung_tu" id="exampleInputPassword1" placeholder="Số chứng từ">
            </div>
        </div><!-- /.box-body -->

        <div class="box-footer">
            <input type="button" class="btn btn-primary" id="thanhtoan" value="Thanh toán" >
        </div>
    </form>
</div>
<script type="text/javascript">
        $('#tien').autoNumeric('init');
        $("#thanhtoan").click(function(event) {
            var count = <?php echo $count; ?>;
            var check = 0;
            if ($('#so_chungtu').val() == '') {
                $('#so_chungtu').addClass('error');
                check = 1;
            };
            if ($('#date').val() == '') {
                $('#date').addClass('error');
                check = 1;
            };
            if (count == 1) {
                var tong_tien = parseInt($('#tong_tien').val());
                var tien = $('#tien').val().replace(',','');
                while(tien.split(',').length != 1){
                    console.log(tien.split(',').length);
                    tien = tien.replace(',','');
                }
                if (tien > tong_tien) {
                    $('#tien').addClass('error');
                    check = 1;      
                }else{
                    $('#value_tien').val(tien);
                }
            };
            if (check == 0) {
                $.ajax({
                    url: "<?php echo Yii::app()->createUrl('/KhachHang/default/chapnhanthanhtoan'); ?>",
                    type: 'POST',
                    data: $('#form_thanhtoan').serialize(),
                    success: function (data) {
                        $('#form_thanhtoan').html(data.info);
                        
                        if (data.status) {
                            setTimeout(function() {
                                $('#div_nhap').fadeOut();
                                $('#save_hoadon').fadeIn();
                            }, 2000);
                            $.fn.yiiGridView.update('doitac-grid1');
                        };
                        
                    }
                });
            };
        });
</script>
<style type="text/css">
input.error{
    border-color: #f56954 !important;
    box-shadow: none;
}
</style>